package threadSynchronization;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: WanqingLiu
 * @Date: 2023/02/02/15:24
 */
public class UnsafeList {
    public static void main(String[] args) throws InterruptedException {
        List<String> list = new ArrayList<>();
        for (int i=0; i<10000; i++){
            // 两个线程覆盖了同一个位置
            new Thread(() ->{
                synchronized (list) {
                    list.add(Thread.currentThread().getName());
                }
            }).start();
        }
        Thread.sleep(1000);
        System.out.println(list.size());
    }

}
